package com.sian.web.security.authentication;

import java.util.Collection;
import java.util.HashSet;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;

@Service("authenticationProvider")
public class AuthenticationProviderImpl implements AuthenticationProvider
{
	@Override
	public Authentication authenticate(Authentication authentication) throws AuthenticationException 
	{
		Collection<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>();
		GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_USER");
		grantedAuthorities.add(grantedAuthority);
		
		return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(),
				authentication.getCredentials(),
				grantedAuthorities);
	}

	@Override
	public boolean supports(Class<?> auth)
	{
		if(UsernamePasswordAuthenticationToken.class.equals(auth))
		{
			return true;
		}

		return false;
	}

}
